<template>
	<view style="height: 100vh;position: relative;background-color: #f2f2f2;">
		<u-navbar :title='title'   left-icon-color="white"  :autoBack="true" :titleStyle="{'color':'white'}" bgColor="#13989a"
			:placeholder="true"></u-navbar>
		<view v-if="patrolType==1">
			<video :autoplay="false" v-if='videoUrl' :src="videoUrl" style="width: 100%;height: 400rpx;"></video>
			<view v-else
				style="background-color: #010101;display: flex;flex-direction: column;justify-content: center;align-items: center;height: 400rpx;">
				<image src='https://renovationcdn.jiachuangnet.com/%E6%91%84%E5%83%8F%E5%A4%B4%E7%A6%BB%E7%BA%BF.png'
					style="width:100rpx;height: 100rpx;margin: 20rpx 0;"></image>
				<view style="text-align: center;height: 90rpx;line-height: 90rpx;color:#e6e6e6;font-size: 28rpx;">
					当前设备不在线 
				</view>
			</view>
		</view>
		<view class="container" :style="{ top: top}">
			<view class="title flex" v-if="patrolType==1"
				style="justify-content: space-between;background-color: #fff;border-radius: 20rpx;padding: 20rpx;align-items: center;margin-bottom: 20rpx;">
				<text @click="videoShow=true">在线|{{serialNumber||'暂无视频'}} ></text>
				<u-icon name="camera-fill" color="#13989a" size="28" @click="getCameraCapture"></u-icon>
			</view>
			<view class="floor flex" style="justify-content: space-around;" v-if="patrolType==2">
				<view class="workItem" @click="signShow=true">
					<u-icon name="map-fill" color="#13989a" size="28"></u-icon>
					<text>{{signImg?'已签到':'未签到'}}</text>
				</view>
				<view style="height: 50rpx;width: 1rpx;background-color: #f3f3f3;">
				</view>
				<view class="workItem" @click="imagePoolShowFn(0)">
					<u-icon name="photo-fill" color="#13989a" size="28"></u-icon>
					<text>图库</text>
				</view>
				<view style="height: 50rpx;width: 1rpx;background-color: #f3f3f3;">
				</view>
				<view class="workItem" @click="toPath(`videoCapture/index?assignTaskId=${assignTaskId}`)">
					<u-icon name="camera-fill" color="#13989a" size="28"
						></u-icon>
					<text>视频抓拍</text>
				</view>

				<!-- <view class="workItem">
					<u-upload :fileList="fileList6" @afterRead="afterRead" @delete="deletePic" name="6" multiple
						:maxCount="1" width="250" height="150">
						<u-icon name="camera-fill" color="#2979ff" size="28"></u-icon>
					</u-upload>
					<text>拍照</text>
				</view> -->
			</view>
			<view class="wrapper">
				<view class="left-box">
					<!-- <view class="switch flex"
						style="font-size: 24rpx;justify-content: center;align-items: center;height: 100rpx;">
						看统计
						<u-icon name="tags" color="#13989a" size="24"></u-icon>
					</view> -->
					<scroll-view style="border-radius: 10rpx;" :style="{ height: heightScroll}" v-if="patrolTemplate"
						scroll-y="true" class="scroll-Y">
						<view id="demo1" class="scroll-view-item uni-bg-red" :class="{'active':activeIndex===i}"
							v-for="(v,i) in patrolTemplate.largeVoList" :key="v.largeId" @click="leftHanlder(i)">
							<view style="color:#13989a ;font-size: 28rpx;font-weight: 700;" class="">
								{{v.largeName}}
							</view>
							<text
								style="color:#c8c8c8 ;font-size: 24rpx;">{{`${v.finishCountLargeId}/${v.largeProblemNum}`}}</text>
						</view>
					</scroll-view>
				</view>
				<view class="right-box" style="margin: 0 20rpx;">
					<scroll-view :style="{ height: heightScroll}" v-if="patrolTemplate" scroll-y="true"
						class="scroll-Y">
						<u-collapse v-if="!load">
							<u-collapse-item :title="v.termName+' '+v.finishCount+'/'+v.termProblemNum"
								name="Docs guide" v-for="(v,i) in patrolTemplate.largeVoList[activeIndex].termVoList"
								:key="v.termId">

								<view class="task" v-for="(item,index) in v.list" :key="item.problemId">
									<view class="tasktital">
										{{`[${item.problemScore}分] `+item.problemName}}
									</view>
									<view class="imageWrapper">
										<view class="flex"
											style="justify-content: center;align-items: center;height: 280rpx;background-color: #f2f2f2;"
											v-if="item.problemImg.length<=0" >
											<image
												src="https://renovationcdn.jiachuangnet.com/%E5%9B%BE%E7%89%87%E4%B8%8A%E4%BC%A0.png"
												mode="" style="height: 100rpx;width: 120rpx;"></image>
										</view>
										<view style="height: 280rpx;overflow-y: auto;" v-else>
											<view style="position: relative;display: inline-block;"  v-for="(url,j) in item.problemImg" :key="j">
												<image @click="viewImage(j,item.problemImg)" :src="'http://'+url" mode=""
													style="width: 120rpx;height: 120rpx;border-radius: 10rpx;margin: 10rpx;">
												</image>
												<view style="position: absolute;right: 0;top: 0;">
													<u-icon name="close-circle-fill" color="#625d5a" size="20"
														 @click="deleteItemImg(i,index,i)"></u-icon>
													
												</view>
											</view>
										</view>

									</view>
									<view class="flex" style="margin: 10rpx 0rpx;">
										<u-input placeholder="请输入备注" v-model="item.problemRemark"></u-input>
										<view class="flex" style="align-items: center;">
											<upload :ref="'upload'+item.problemId" :fileListInit="item.problemImg"
												name="overImage" @uploadFile="uploadImge($event,i,index)"
												v-show="false">

											</upload>
											<u-icon name="camera-fill" color="#13989a" size="28"
												@click="uploadImgHandler(item.problemId)" v-if="patrolType==2"></u-icon>
											<u-icon v-if="patrolType==1" name="camera-fill" color="#13989a" size="28"
												@click="getCameraCapture(1,i,index)"></u-icon>
											<view style="height: 50rpx;width: 1rpx;background-color: #f3f3f3;"></view>
											<u-icon name="photo-fill" color="#13989a" size="28"
												@click="imagePoolShowFn(1,i,index)"></u-icon>
										</view>
									</view>
									<view style="margin: 10rpx 0rpx;">
										<u-input placeholder="扣分 0.0" v-if="item.isQualified==0" disabled></u-input>
										<u-input placeholder="扣分 0.0" v-else
											:value="item.isQualified==1?'扣分 '+0:'扣分 - '+item.problemScore"
											disabled></u-input>
									</view>
									<view style="margin: 10rpx 0rpx;" class="flex">
										<view class="isOk" style="width: 100rpx;margin-right: 20rpx;">
											<u-button text="合格" size="mini" :type="item.isQualified==1?'primary':''"
												@click="qualifiedHandler(1,i,index)"></u-button>
										</view>
										<view style="width: 100rpx;" @click="qualifiedHandler(2,i,index)">
											<u-button text="不合格" :type="item.isQualified==2?'warning':''"
												size="mini"></u-button>
										</view>
									</view>
									<view style="height: 2rpx;background-color: #c8c8c8;margin: 10rpx;"
										v-if="v.termProblemNum!=index+1">
									</view>
								</view>
							</u-collapse-item>
						</u-collapse>
					</scroll-view>

				</view>
			</view>
			<view class="footer flex" style="justify-content: space-between;padding-top: 20rpx;padding-bottom: 10rpx;">
				<view class="flex"
					style="position: absolute;top: 0;right: 0;left: 0;justify-content: space-between;padding: 5rpx 20rpx;background-color: #f3edd5;font-size: 20rpx;">
					<view class="" v-if="patrolTemplate&&patrolTemplate.totalProblem">
						{{`${finishCount}/${patrolTemplate.totalProblem}`}}
					</view>
					<view class="">
						考评时长 {{time}}
					</view>
				</view>
				<view class="footer-left flex" style="justify-content: center;align-items: center;">
					<view class="workItem" style="flex-direction: column;width: 100rpx;" @click="detailShow=true">
						<u-icon name="tags" color="#13989a" size="28"></u-icon>
						<text>详情</text>
					</view>
					<view style="height: 80rpx;width: 1rpx;background-color: #f3f3f3;margin: 0 30rpx;">
					</view>
					<view class="workItem" style="flex-direction: column;width: 310rpx;align-items: flex-start;">
						<text style="color: #13989a;font-weight: 700;">{{patrolScore}}.0分</text>
						<text>考评总分：{{fullScore}}.0分</text>
					</view>
				</view>
				<view class="footer-right flex"
					style="justify-content: flex-end;align-items: center;flex: 1;padding-right: 20rpx;">
					<view style="margin: 10rpx 0rpx;" class="flex">
						<!-- <view style="width: 150rpx;margin-right: 20rpx;">
							<u-button text="保存草稿" :plain="true" type="primary"></u-button>
						</view> -->
						<view style="width: 150rpx;">
							<u-button text="提交" size="small" type="primary" color="#13989a" @click="scoreShow=true"></u-button>
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-popup :show="imagePoolShow" @close="imagePoolShow=false" round="10" mode="bottom">
			<view class="overdueForm" style="padding-top: 20rpx;min-height: 50vh;">
				<view style="text-align: center;font-size: 30rpx;margin-bottom: 50rpx;">
					视频抓拍列表
				</view>
				<!-- <u-subsection activeColor="#13989A" :list="list" :current="current"
					@change="sectionChange"></u-subsection> -->
				<view style="margin-top: 20rpx;min-height: 50vh;max-height: 70vh;overflow-y: auto;">
					<u-grid :border="false" col="3">
						<u-grid-item v-for="(listItem,listIndex) in videoCaptureObjList" :key="listIndex">
							<view style="position: relative;">
								<image :src="'http://'+listItem.url" @click="viewImage(listIndex,videoCaptureList)"
									style="width: 25vw;height: 25vw;" mode="aspectFill"></image>
								<view style="position: absolute;right: 0;top: 0;">
									<u-icon name="close-circle-fill" color="#625d5a" size="20"
										v-if="!isChoocsImg" @click="deletePool(listIndex)"></u-icon>
									<view v-else @click="chooseImg(listIndex)">
										<u-icon name="checkmark-circle-fill" color="#13989a" size="20"
											v-if="listItem.isChoose"></u-icon>
										<u-icon name="checkmark-circle-fill" color="#ffffff" size="20" v-else></u-icon>
									</view>
								</view>
							</view>
							<!-- <text class="grid-text">{{listIndex}}</text> -->
						</u-grid-item>
					</u-grid>
				</view>
				<view style="background-color: #fff;padding: 10rpx 20rpx;" v-if="isChoocsImg">
					<u-button shape="circle" color='#13989a' @click="addImgFn">添加</u-button>
				</view>
			</view>
		</u-popup>
		<u-popup :show="signShow" @close="signShow=false" round="10" mode="bottom">
			<view class="overdueForm" style="padding-top: 20rpx;">
				<view style="text-align: center;font-size: 30rpx;margin-bottom: 50rpx;">
					签到
				</view>
				<view style="padding: 0 20rpx;margin-bottom: 100rpx;">
					<view class="flex" v-if="!signImg"
						style="justify-content: center;align-items: center;height: 400rpx;background-color: #f2f2f2;"
						@click="signHandler">
						<image src="https://renovationcdn.jiachuangnet.com/%E5%9B%BE%E7%89%87%E4%B8%8A%E4%BC%A0.png"
							mode="" style="height: 100rpx;width: 120rpx;"></image>
					</view>
					<image v-else :src="'http://'+signImg" mode="" style="height: 400rpx;width: 100%;"
						@click="signHandler">
					</image>
				</view>
				<upload ref="sign" name="overImage" @uploadFile="uploadSign" v-show="false">
				</upload>
				<view style="background-color: #fff;padding: 10rpx 20rpx;margin-bottom: 50rpx;">
					<u-button shape="circle" color='#13989a' @click="signShow=false">签到</u-button>
				</view>
			</view>
		</u-popup>
		<u-popup :show="detailShow" @close="detailShow=false" round="10" mode="bottom">
			<view class="overdueForm" style="padding-top: 20rpx;">
				<view style="text-align: center;font-size: 30rpx;margin-bottom: 50rpx;">
					门店概览
				</view>
				<view class="floor" style="background-color: #f7f7f7;border: 20rpx;">
					<view class="title flex" style="justify-content: space-between;margin-bottom: 10rpx;">
						<text>近三十天不合格项前5</text>
						<text style="color: #c8c8c8;font-size: 24rpx;">次数</text>
					</view>
					<view v-if="isNotOkTop5List.length>0">
						<view class="flex" v-for="(v,i) in isNotOkTop5List" :key="i"
							style="justify-content: space-between;margin: 0 10rpx; font-size: 28rpx;">
							<text>{{v.problemName}}</text>
							<text>{{v.unqualifiedCount}}</text>
						</view>
					</view>
					<view v-else>
						暂无记录
					</view>
					<view style="text-align: center;color: #13989a;margin: 20rpx;"
						@click="toPath(`log/noPassList?assignTaskId=${assignTaskId}`)">
						查看更多
					</view>
				</view>
				<view class="flex" style="margin: 30rpx;margin-bottom: 100rpx;">
					<!-- <view class="workItem flex" style="background-color: #f7f7f7;border: 20rpx;padding: 20rpx;"
						@click="toPathC('oLineAssessment')">
						<u-icon name="tags" color="#746a69" size="28"></u-icon>
						<text>门店信息</text>
					</view> -->
					<view class="workItem" @click="toPath(`log/history?assignTaskId=${assignTaskId}`)"
						style="background-color: #f7f7f7;border: 20rpx;padding: 20rpx;">
						<u-icon name="tags" color="#746a69" size="28"></u-icon>
						<text>巡查记录</text>
					</view>
				</view>

			</view>
		</u-popup>
		<u-popup :show="scoreShow" @close="scoreShow=false" round="10" mode="bottom">
			<view class="overdueForm">
				<view class="scoreBox flex"
					style="flex-direction: column; justify-content: center;align-items: center;background-color: #fff;border-radius: 50rpx;">
					<view style="font-size: 40rpx;color: #13989a;margin: 20rpx;">
						{{patrolScore}}.0分
					</view>
					<view style="color: #535353;font-size: 24rpx;margin: 20rpx;">
						<text>考评总分：{{fullScore}}.0</text>
						<!-- <text style="margin: 20rpx;">|</text>
						<text>得分率：{{patrolScore/fullScore}}%</text> -->
					</view>
					<view class="flex" style="margin: 20rpx;">
						<view class="flex" style="flex-direction: column;align-items: center;justify-content: center;">
							<text>{{isOkCount}}</text>
							<text style="color: #535353;font-size: 24rpx;">合格</text>
						</view>
						<text style="margin: 20rpx;">|</text>
						<view class="flex" style="flex-direction: column;align-items: center;">
							<text>{{isNotOkCount}}</text>
							<text style="color: #535353;font-size: 24rpx;">不合格</text>
						</view>
						<text style="margin: 20rpx;">|</text>
						<view class="flex" style="flex-direction: column;align-items: center;" v-if="patrolTemplate&&patrolTemplate.totalProblem">
							<text>{{patrolTemplate.totalProblem-isOkCount - isNotOkCount}}</text>
							<text style="color: #535353;font-size: 24rpx;">未评</text>
						</view>
					</view>
				</view>
				<view style="line-height: 60rpx;background-color: #f7f7f7;">
					<text style="border-left: 10rpx solid #13989a;margin: 0 30rpx;"></text>
					考评总结
				</view>
				<view class="floor">
					<view class="title">
						考评意见
					</view>
					<u-input placeholder="点击输入考评意见" v-model="spotCheckRemark"></u-input>
				</view>
				<view style="height: 100rpx;background-color: #f7f7f7;">
				</view>
				<view style="background-color: #fff;padding: 10rpx 20rpx;">
					<u-button shape="circle" color='#13989a' @click="addPatrolRecord">提交</u-button>
				</view>
			</view>
		</u-popup>
		<u-popup :show="videoShow" @close="videoShow=false" round="10" mode="bottom">
			<view class="overdueForm">
				<view style="text-align: center;font-size: 30rpx;margin-bottom: 50rpx;">
					摄像头
				</view>
				<view class="videoWrapper">
					<view v-if="videoList.length>0"
						style="display: flex; flex-wrap: wrap; justify-content: space-between;">
						<view class="item" v-for="(v,i) in videoList" :key="i"
							style="width: 40vw;border: 1rpx solid #eee;border-radius: 10rpx;margin: 20rpx;">
							<video :autoplay="true" :id="myVideo+'i'" v-if='v.videoUrl && v.showRealVideo'
								:src="v.videoUrl" style="width: 100%;height: 204rpx;"></video>
							<!-- 伪装播放按钮（未加载时显示） -->
							<view v-if="v.videoUrl && !v.showRealVideo"
								style="width: 100%;height: 204rpx;background-color: #eee;display: flex;justify-content: center;align-items: center;"
								@click="initVideo(i)">
								<view class="play-icon" style="font-size: 40rpx;color: #333;">▶</view>
							</view>
							<view v-if="!v.videoUrl">
								<image src='https://renovationcdn.jiachuangnet.com/novideo.jpg'
									style="width: 100%;height: 100rpx;"></image>
								<view
									style="text-align: center;height: 90rpx;line-height: 90rpx;color:#e6e6e6;font-size: 24rpx;">
									当前店铺暂无实时画面</view>
							</view>
							<view
								style="padding: 20rpx 10rpx;font-size: 24rpx;font-weight: 500;;border-top:0.5px solid #eee;color: #2979ff;"
								v-if="v.serialNumber==serialNumber">
								{{v.serialNumber}}

							</view>
							<view v-else
								style="padding: 20rpx 10rpx;font-size: 24rpx;font-weight: 500;;border-top:0.5px solid #eee;">
								{{v.serialNumber}}
							</view>
						</view>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	let app = getApp();
	export default {
		data() {
			return {
				videoUrl: null,
				videoList: [],
				videoCaptureList: [],
				serialNumber: null,
				detailShow: false,
				signShow: false,
				videoShow: false,
				current: 0,
				imagePoolShow: false,
				assignTaskId: 0,
				scoreShow: false,
				isChoocsImg: false,
				templateId: 0,
				patrolTemplate: null,
				activeIndex: 0,
				fullScore: 0,
				spotCheckRemark: '',
				isSign: 0,
				signImg: '',
				videoCaptureList: [],
				videoCaptureObjList: [],
				imgTermIndex: 0,
				imgProblemIndex: 0,
				scrollTop: 0,
				old: {
					scrollTop: 0
				},
				load: false,
				time: '',
				timerId: null,
				seconds: 0,
				isNotOkTop5List: [],
				patrolType: 0,
				title: '',
				videoList: '',
				heightScroll: '68vh',
				top: '150rpx',
				autoPatrolPlanId:null,
				autoPatrolPlanDetailId:null
			}
		},
		onLoad(option) {
			if (option.templateId) {
				this.templateId = option.templateId
				this.assignTaskId = option.assignTaskId
				this.patrolType = option.patrolType
				if (this.patrolType == 1) {
					this.title = '在线考评'
					this.getViedoList()
					this.heightScroll = '50vh'
					this.top = '560rpx'
					this.signShow = false
				} else {
					this.title = '线下考评'
					this.heightScroll = '70vh'
					this.top = '176rpx'
					this.signShow = true
				}
				this.getLargeVo()
			}
			if(option.autoPatrolPlanId){
				this.autoPatrolPlanId=option.autoPatrolPlanId
				this.autoPatrolPlanDetailId=option.autoPatrolPlanDetailId
			}
			this.startTimer()
			this.getPatrolRecordVo()
		},
		onShow() {
			let app = getApp();
			this.videoCaptureList= app.globalData.videoCaptureList
			this.videoCaptureObjList = this.videoCaptureList.map(url => {
				return {
					url,
					isChoose: false
				}
			})

		},
		computed: {

			isOkCount() {
				let total = 0
				if (this.patrolTemplate) {
					this.patrolTemplate.largeVoList.forEach((v, i) => {
						v.termVoList.forEach((item, index) => {
							item.list.forEach((problemItem, problemIndex) => {
								if (problemItem.isQualified == 1) {
									total += 1
								}
							})
						})
					})
					return total
				} else {
					return 0
				}
			},
			isNotOkCount() {
				let total = 0
				if (this.patrolTemplate) {
					this.patrolTemplate.largeVoList.forEach((v, i) => {
						v.termVoList.forEach((item, index) => {
							item.list.forEach((problemItem, problemIndex) => {
								if (problemItem.isQualified == 2) {
									total += 1
								}
							})
						})
					})
					return total
				} else {
					return 0
				}
			},
			finishCount() {
				let count = 0
				if (this.patrolTemplate) {
					this.patrolTemplate.largeVoList.forEach((v, i) => {
						count += v.finishCountLargeId
					})
					return count
				} else {
					return 0
				}
			},
			patrolScore() {
				let total = 0
				if (this.patrolTemplate) {
					this.patrolTemplate.largeVoList.forEach((v, i) => {
						v.termVoList.forEach((item, index) => {
							item.list.forEach((problemItem, problemIndex) => {
								if (problemItem.isQualified == 1) {
									total += problemItem.problemScore
								}
							})
						})
					})
					return total
				} else {
					return 0
				}

			}
		},
		onUnload() {
			clearInterval(this.timerId);
		},
		methods: {
			deleteItemImg(termIndex, problemIndex,i){
				this.patrolTemplate.largeVoList[this.activeIndex].termVoList[termIndex].list[problemIndex].problemImg.splice(i,1)
			},
			deletePool(i){
				this.videoCaptureObjList.splice(i,1)
				this.videoCaptureList.splice(i,1)
			},
			getCameraCapture(flag, termIndex, problemIndex) {
				if (this.videoUrl) {
					uni.$u.http.get('/patrol/getCameraCapture', {
						params: {
							serialNumber: this.serialNumber,
						}
					}).then(res => {
						if (res) {
							this.videoCaptureList.push(res)
							this.videoCaptureObjList.push({
								url: res,
								isChoose: false
							})
							if (flag) {
								let init = this.patrolTemplate.largeVoList[this.activeIndex].termVoList[termIndex]
									.list[problemIndex]
									.problemImg
								this.patrolTemplate.largeVoList[this.activeIndex].termVoList[termIndex].list[
									problemIndex].problemImg = [
									...init, res
								]
							}
						}
					})
				} else {
					uni.$u.toast('当前选中摄像头不在线，无法抓图 :)');
				}

			},
			initVideo(i) {
				this.videoUrl = this.videoList[i].videoUrl
				this.serialNumber = this.videoList[i].serialNumber
				// this.videoList[i].showRealVideo=true
			},
			getViedoList() {
				uni.$u.http.get('/patrol/getStoreAllCamera', {
					params: {
						assignTaskId: this.assignTaskId,
					}
				}).then(res => {
					if (res) {
						this.videoList = res.map(item => {
							return {
								serialNumber: item.serialNumber,
								videoUrl: item.videoUrl,
								showRealVideo: false
							}
						})
						if (this.videoList.length > 0) {
							this.initVideo(0)
						}
					}
				})
			},
			getPatrolRecordVo() {
				uni.$u.http.post('/patrol/getPatrolRecordVo', {
					pageNumber: 1,
					pageSize: 5,
					assignTaskId: this.assignTaskId,
					flag: 3
				}).then(res => {
					if (res) {
						this.isNotOkTop5List = res.data
					}
				})
			},
			startTimer() {
				if (!this.timerId) {
					this.timerId = setInterval(() => {
						this.seconds++;
						const hours = Math.floor(this.seconds / 3600);
						const minutes = Math.floor((this.seconds % 3600) / 60);
						const secs = this.seconds % 60;
						this.time = [
							hours.toString().padStart(2, '0'),
							minutes.toString().padStart(2, '0'),
							secs.toString().padStart(2, '0')
						].join(':');
					}, 1000);
				}
			},
			leftHanlder(i) {
				this.activeIndex = i
				this.load = true
				setTimeout(() => {
					this.load = false
				}, 50)
			},
			scroll(e) {
				console.log(e)
				this.old.scrollTop = e.detail.scrollTop
			},
			addImgFn() {
				let filterArrImg = []
				this.videoCaptureObjList.forEach(item => {
					if (item.isChoose) {
						item.isChoose = false
						filterArrImg.push(item.url)
					}
				})
				let inti = this.patrolTemplate.largeVoList[this.activeIndex].termVoList[this.imgTermIndex].list[this
					.imgProblemIndex].problemImg
				this.patrolTemplate.largeVoList[this.activeIndex].termVoList[this.imgTermIndex].list[this.imgProblemIndex]
					.problemImg = [...inti, ...filterArrImg]

				this.imagePoolShow = false

			},
			chooseImg(index) {
				this.videoCaptureObjList[index].isChoose = !this.videoCaptureObjList[index].isChoose
			},
			uploadSign(msg) {
				this.signImg = msg.files[msg.files.length - 1]
			},
			addPatrolRecord() {
				if (this.patrolTemplate.totalProblem - this.isOkCount - this.isNotOkCount > 0) {
					return uni.$u.toast('有未巡查到的项目，无法提交');
				}
				let list = []
				this.patrolTemplate.largeVoList.forEach((v, i) => {
					v.termVoList.forEach((item, index) => {
						item.list.forEach((problemItem, problemIndex) => {
							let obj = {
								isQualified: problemItem.isQualified,
								largeId: v.largeId,
								termId: item.termId,
								problemId: problemItem.problemId,
								recordScore: problemItem.recordScore,
								problemImg:problemItem.problemImg.join(',')
							}
							list.push(obj)
						})
					})
				})
				
				uni.$u.http.post('/patrol/addPatrolRecord', {
					patrolTemplateId: Number(this.templateId),
					assignTaskId: Number(this.assignTaskId),
					fullScore: this.fullScore,
					patrolScore: this.patrolScore,
					patrolType: this.patrolType, //1 在线巡查 2 线下巡查 3 在线点检 4 线下点检
					list,
					spotCheckRemark: this.spotCheckRemark,
					signImg: this.signImg,
					autoPatrolPlanId:this.autoPatrolPlanId,
					autoPatrolPlanDetailId:this.autoPatrolPlanDetailId
				}).then(res => {
					if (res) {
						uni.showToast({
							title: '提交成功',
							duration: 1000,
							mask: true,
							complete: () => {
								setTimeout(() => {
									uni.redirectTo({
										url: `/packageC/pages/workbench/index`
									})
								}, 1000)
							}
						});
					}
				})
			},
			signHandler() {
				this.$refs['sign'].clickUpload()

			},
			uploadImgHandler(id) {
				let key = 'upload' + id
				let a = this.$refs[key]
				console.log(a)
				if (a.length) {
					a[0].clickUpload()
				}
			},
			uploadImge(msg, termIndex, problemIndex) {
				let init = this.patrolTemplate.largeVoList[this.activeIndex].termVoList[termIndex].list[problemIndex]
					.problemImg
				this.patrolTemplate.largeVoList[this.activeIndex].termVoList[termIndex].list[problemIndex].problemImg = [
					...init, msg.files[msg.files.length - 1]
				]
			},
			qualifiedHandler(val, termIndex, problemIndex) {
				let flag = this.patrolTemplate.largeVoList[this.activeIndex].termVoList[termIndex].list[problemIndex]
					.isQualified
				if (flag == 0) {
					console.log(flag)
					this.patrolTemplate.largeVoList[this.activeIndex].termVoList[termIndex].finishCount += 1
					this.patrolTemplate.largeVoList[this.activeIndex].finishCountLargeId += 1
				}
				this.patrolTemplate.largeVoList[this.activeIndex].termVoList[termIndex].list[problemIndex].isQualified =
					val

			},
			getLargeVo() {
				uni.$u.http.get('/patrol/getPatrolTemplateConfig', {
					params: {
						templateId: this.templateId
					}
				}).then(res => {
					if (res) {
						this.fullScore = res.totalScore
						res.largeVoList.forEach((v, i) => {
							v.finishCountLargeId = 0
							v.termVoList.forEach((item, index) => {
								item.finishCount = 0
								item.list.forEach((problemItem, problemIndex) => {
									problemItem.isQualified = 0
									problemItem.recordScore = problemItem.problemScore
									problemItem.problemImg = [],
										problemItem.problemRemark = null
								})
							})
						})
						this.patrolTemplate = res
					}
				})
			},
			imagePoolShowFn(flag, termIndex, problemIndex) {
				this.imagePoolShow = true
				if (flag) {
					// 从图库选择
					this.isChoocsImg = true
					this.imgTermIndex = termIndex
					this.imgProblemIndex = problemIndex
					console.log(problemIndex)
				} else {
					//编辑图库
					this.isChoocsImg = false
				}
			},
			viewImage(listIndex,list) {
				let imageList= list.map(item=>'http://'+item)
				uni.previewImage({
					current: listIndex,
					urls: imageList,
					longPressActions: {
						itemList: ['保存图片'],
						success: data => {
							uni.closePreviewImage()
							/* 保存图片到系统相册 */
							if (data.tapIndex == 0) {
								uni.getImageInfo({
									src: imageList[listIndex],
									success: function(res) {
										console.log(res)
										uni.saveImageToPhotosAlbum({ //保存图片到系统相册。
											filePath: res.path, //图片文件路径
											success: function() {
												uni.showToast({
													title: '图片保存成功',
													icon: 'none',
												});
											},
											fail: function(e) {
												console.log(e);
												uni.showToast({
													title: '图片保存失败',
													icon: 'none',
												});
											},
										});
									},
									fail: function(e) {
										console.log(e);
										uni.closePreviewImage()
										uni.showToast({
											title: '图片保存失败',
											icon: 'none',
										});
									},
								})
							}
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			},
			imageFn() {
				uni.chooseImage({
					count: 6, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function(res) {
						console.log(JSON.stringify(res.tempFilePaths));
					}
				});
			},
			sectionChange(e) {
				this.current = e
			},
			blurSearch() {

			},
			toPath(url) {
				if ('videoCapture'.includes(url)) {
					let app = getApp();
					app.globalData.videoCaptureList = JSON.parse(JSON.stringify(this.videoCaptureList))
				}
				uni.navigateTo({
					url: `/packageC/pages/${url}`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep.isOk{
		.u-button--primary{
			background-color:#13989a;
			border-color:#13989a;
		}
	}
	.active {
		background-color: #fff;
	}

	.overdueForm {
		// background-color: #f7f7f7;
	}

	.task {
		// height: 50rpx;
		// overflow-y:scroll;
	}

	::v-deep.right-box {
		.u-collapse-item {
			font-weight: 700;
			background-color: #fff;
			border-radius: 10rpx;
			margin-bottom: 10rpx;
		}

		.u-collapse-item__content {}

		.u-line {
			border: unset;
		}

		.u-input {
			background-color: #f7f7f7;
		}
	}

	.footer {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		height: 124rpx;
		background-color: #ffffff;
	}

	.wrapper {
		display: flex;
	}

	.left-box {
		background-color: #f7f7f7;
	}

	.scroll-view-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		height: 100rpx;
		width: 180rpx;
	}

	.workItem {
		font-size: 24rpx;
		width: 150rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		flex: 1;
		margin: 0 10rpx;
	}

	.container {
		width: 100vw;
		z-index: 10;
		position: absolute;
		overflow: hidden;
		border-radius: 20rpx;
	}

	.workerSearch {
		border-radius: 40rpx;
		display: flex;
		align-items: center;
		padding-left: 22rpx;
		width: 100%rpx;
		height: 60rpx;
		background-color: #e6e6e6;
		opacity: 0.9;
		margin: 10rpx 0;
	}

	.floor {
		background-color: #fff;
		border-radius: 10rpx;
		padding: 20rpx;
		margin: 30rpx;
		margin-bottom: 20rpx;

		.title {
			font-weight: 600;
			font-size: 30rpx;
		}
	}
</style>